package com.cj.mobile.iabp.mvp.ui.activity;

import static com.jess.arms.utils.Preconditions.checkNotNull;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.TypedValue;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.cj.mobile.iabp.R;
import com.cj.mobile.iabp.app.utils.CommonUtils;
import com.cj.mobile.iabp.di.component.DaggerArchiveInfoComponent;
import com.cj.mobile.iabp.mvp.contract.ArchiveInfoContract;
import com.cj.mobile.iabp.mvp.model.entity.ArchiveInfo;
import com.cj.mobile.iabp.mvp.presenter.ArchiveInfoPresenter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import butterknife.BindView;

/**
 * Created on 2025/10/01 21:52
 * 查看归档信息
 *
 * @author Love_xie
 * module name is ArchiveInfoActivity
 */
public class ArchiveInfoActivity extends BaseActivity<ArchiveInfoPresenter> implements ArchiveInfoContract.View {
    /*----------------------------------------------------------------控件信息----------------------------------------------------------------*/
    @BindView(R.id.txvi_archiveinfo_code)
    TextView txviCode;                                                                              // 登记号
    @BindView(R.id.txvi_archiveinfo_name)
    TextView txviName;                                                                              // 患者姓名

    @BindView(R.id.txvi_archiveinfo_status)
    TextView txviStatus;                                                                            // 归档
    @BindView(R.id.txvi_archiveinfo_state)
    TextView txviState;                                                                             // 患者状态
    @BindView(R.id.txvi_archiveinfo_ga)
    TextView txviGa;                                                                                // 肌钙蛋白
    @BindView(R.id.txvi_archiveinfo_zsszmqnj)
    TextView txviZsszmqnj;                                                                          // 出院前左室舒张末期内径
    @BindView(R.id.txvi_archiveinfo_zssxfs)
    TextView txviZssxfs;                                                                            // 出院前左室射血分数
    @BindView(R.id.txvi_archiveinfo_zyzd)
    TextView txviZyzd;                                                                              // 主要诊断
    @BindView(R.id.txvi_archiveinfo_cyzd)
    TextView txviCyzd;                                                                              // 次要诊断
    @BindView(R.id.txvi_archiveinfo_other)
    TextView txviOther;                                                                             // 其它诊断
    @BindView(R.id.txvi_archiveinfo_icu)
    TextView txviIcu;                                                                               // ICU
    @BindView(R.id.txvi_archiveinfo_mc)
    TextView txviMc;                                                                                // 机械通气时间
    @BindView(R.id.txvi_archiveinfo_zyts)
    TextView txviZyts;                                                                              // 住院天数
    /*----------------------------------------------------------------业务信息----------------------------------------------------------------*/
    // 数据源
    private ArchiveInfo info;

    // 患者姓名
    private String name;
    // 登记号
    private String code;

    /**
     * 根据主题使用不同的颜色。
     * 如果想要纯透明，则需要重写此方法，返回值为 -1 即可。
     */
    public int useStatusBarColor() {
        TypedValue typedValue = new TypedValue();
        getTheme().resolveAttribute(android.R.color.white, typedValue, true);
        return typedValue.data;
    }

    /**
     * 将状态栏改为浅色模式(状态栏 icon 和字体会变成深色)
     */
    public boolean useLightStatusBar() {
        return true;
    }

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerArchiveInfoComponent
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_archive_info;
    }

    public void getBundleValues(Bundle bundle) {
        if (bundle != null) {
            info = bundle.getParcelable("info");
            code = bundle.getString("code");
            name = bundle.getString("name");
        }
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        setTitle("归档信息");

        getBundleValues(getIntent().getExtras());

        loadData();
    }

    private void loadData() {
        if (info != null) {
            txviCode.setText(CommonUtils.isEmptyReturnStr(code, "暂无"));
            txviName.setText(CommonUtils.isEmptyReturnStr(name));
            txviStatus.setText(CommonUtils.isEmptyReturnStr(info.getStatus()));
            txviState.setText(CommonUtils.isEmptyReturnStr(info.getAlive()));
            txviGa.setText(CommonUtils.isEmptyReturnStr(info.getGa()));
            txviZsszmqnj.setText(CommonUtils.isEmptyReturnStr(info.getLeftSize()));
            txviZssxfs.setText(CommonUtils.isEmptyReturnStr(info.getLeftScore()));
            txviZyzd.setText(CommonUtils.isEmptyReturnStr(info.getDiagMain()));
            txviCyzd.setText(CommonUtils.isEmptyReturnStr(info.getDiagSec()));
            txviOther.setText(CommonUtils.isEmptyReturnStr(info.getDiagContent()));
            txviIcu.setText(CommonUtils.isEmptyReturnStr(info.getTimeIcu()));
            txviMc.setText(CommonUtils.isEmptyReturnStr(info.getTimeMc()));
            txviZyts.setText(CommonUtils.isEmptyReturnStr(info.getRunTime()));

        }
    }

    @Override
    public Activity getActivity() {
        return this;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }
}